package com.rest.demo.functional.strean;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

/**
 * @author Administrator
 * @decription
 * @Date 2018-01-29 10:32
 */
public class PropertyDemo {
    public static void main(String[] args) {
        Property p1 = new Property("叫了个鸡", 1000, 500, 2);
        Property p2 = new Property("张三丰饺子馆", 2300, 1500, 3);
        Property p3 = new Property("永和大王", 580, 3000, 1);
        Property p4 = new Property("肯德基", 6000, 200, 4);
        List<Property> propertyList = Arrays.asList(p1,p2,p3,p4);
        String name = propertyList
                .stream()
                .sorted(Comparator.comparingInt(property -> property.getDistance()))
                .findFirst()
                .get()
                .getName();
        System.out.println("离我距离最近的是:"+name);

        Long count = propertyList
                .stream()
                .filter(property -> property.getScale() > 1000)
                .count();
        System.out.println("价格大于1000的有"+count+"个");

        List<Property> propertyLimit = propertyList.stream()
                .sorted(Comparator.comparingInt(property -> property.getDistance()))
                .limit(2)
                .collect(Collectors.toList());

        propertyLimit.stream().forEach(System.out::println);

        Map<String,Object> propertyLimitMap = propertyList.stream()
                .sorted(Comparator.comparingInt(property -> property.getDistance()))
                .limit(2)
                .collect(Collectors.toMap(Property::getName,Property::getDistance));
        System.out.println(propertyLimitMap);
    }
}
